组件定义名="智能"
关键词位置= 组件定义名=~ /铰链|智能|参数|侧封板/
关键词位置==nil

arr = [1, 2, 3]
arr.include?(1, 2)

arr = [1, 2, 3]
arr.delete(1)
arr

def test_callee
  caller_locations(1,1)[0].label
end
def test_method
  test_callee
end
puts test_method



# text = "rails 是 rails,  Ruby on Rails 非常好的 Ruby 框架Rails_排版yyy"
text = "rails 是 rails,  Ruby on Rails 非常好的 Ruby 框架Rails_sdfyyy"
text.gsub!(/_排版\S*/, "")

@model = Sketchup.active_model
selection = @model.selection
p selection[0]

entities = Sketchup.active_model.entities
entities.each {|e|
  p e.hidden?
}

@model = Sketchup.active_model
@entities = @model.active_entities
@selection = @model.selection
p @selection.contains?(entity)


@不含板字组件=[]
@含板字组件=[]
@板字上层组件=[]
entities = Sketchup.active_model.entities
entities.each {|e|
  递归识别组件(e)
}
@不含板字组件.each {|e|
  n=e.definition.name
  p n
  e.erase!
}



entities = kk.definition.entities
列出子件(entities)

e = Sketchup.active_model.entities[0]
e.is_a?( Sketchup::ComponentInstance ||Sketchup::ComponentInstance)

componentdefinition = Sketchup.active_model.definitions[0]
entities = componentdefinition.entities
entities.each {|e|
  p e
  # p e.name
}

model = Sketchup.active_model
definitions = model.definitions
kk=definitions['平板门#8'].name

@model = Sketchup.active_model
p  @model.definitions.length
@model.definitions.each {|e|
  p e
  p e.name
}

model = Sketchup.active_model
p model.layers.size
model.layers.purge_unused
p model.layers.size

model = Sketchup.active_model
层s=model.layers
层s.each {|e|
  p e
  if e.name=~ /五金/
    层s.remove(e,true)
  end
}


model = Sketchup.active_model
p  model.definitions.length
model.definitions.purge_unused
p  model.definitions.length

def self.erase_hidden( model, scope, each_options )
  entity_count = self.count_scope_entity( scope, model, each_options )
  progress = TT::Progressbar.new( entity_count, 'Erasing hidden entities' )
  e = nil # Init variables for speed
  count = self.each_entity_in_scope( scope, model, each_options ) { |e|
    progress.next
    erased = false
    if e.valid?
      if e.is_a?( Sketchup::Edge )
        # Edges needs to be checked further
        if e.hidden? || e.soft? || !e.layer.visible?
          unless self.edge_protected?( e )
            e.erase!
            erased = true
          end
        end
      elsif e.hidden? || !e.layer.visible?
        # Everything else is safe to erase.
        e.erase!
        erased = true
      end # if edge?
    end
    erased
  }
end

model = Sketchup.active_model
p  model.definitions.length
model.definitions.purge_unused
p  model.definitions.length
删除多余元素(model.entities)
for e in model.entities.to_a
  if !(e.is_a?( Sketchup::Face ) || e.is_a?( Sketchup::ComponentInstance ) || e.is_a?( Sketchup::Group )) then
    if e.is_a?( Sketchup::Edge )
      faces = e.faces
      p faces.size
      if faces.size<1
         e.erase!
      end
    else
      e.erase!
    end
  end
end
for d in model.definitions
  for e in d.entities.to_a
    if !(e.is_a?( Sketchup::Face ) || e.is_a?( Sketchup::ComponentInstance ) || e.is_a?( Sketchup::Group )) then
      if e.is_a?( Sketchup::Edge )
        faces = e.faces
        p faces.size
        if faces.size<1
           e.erase!
        end
      else
        e.erase!
      end
    end
  end
end

def 删除多余元素(entities)
  for e in entities.to_a
    if e.is_a?( Sketchup::ComponentInstance ) || e.is_a?( Sketchup::Group )
      删除多余元素(e.entities)
    elsif e.is_a?( Sketchup::Edge )
      faces = e.faces
      p faces.size
      if faces.size<1
          e.erase!
      end
    else !e.is_a?( Sketchup::Face )
      e.erase!
    end
  end
end

  @model = Sketchup.active_model
  c = 0
  for e in @model.entities.to_a
    p e
    c = c.next if yield( e )
  end
  for d in @model.definitions
    for e in d.entities.to_a
      p e
      c = c.next if yield( e )
    end
  end
  c
  p c
end


@model = Sketchup.active_model
file=@model.path
文件名 = File.basename(file, '.*')
路径 = File.dirname(file).freeze
全名=路径+'/'+文件名+'_排版'+'.skp'

    def self.create_cube
      @model = Sketchup.active_model
      @model.start_operation('Create Cube', true)
      group = @model.active_entities.add_group
      entities = group.entities
      points = [
        Geom::Point3d.new(0,   0,   0),
        Geom::Point3d.new(1.m, 0,   0),
        Geom::Point3d.new(1.m, 1.m, 0),
        Geom::Point3d.new(0,   1.m, 0)
      ]
      face = entities.add_face(points)
      face.pushpull(-1.m)
      @model.commit_operation
    end

@model = Sketchup.active_model
@entities = @model.active_entities
@entities.each{|e|
  p e.to_s
  # p e.definition.name.to_s
  # p e.parent.definition.name.to_s
  p e.parent.to_s
  p e.parent.name.to_s
  if e.parent.kind_of? Sketchup::@model
    p "编辑顶层"
  else
    p "编辑组件"
  end
}

@selection = @model.selection
@编辑中tr=@model.edit_transform
@原点 = Geom::Point3d.new(0,0,0)
@编辑中局部原点=@原点.transform(@编辑中tr)

@model = Sketchup.active_model
@编辑中组件tr=Sketchup.active_model.edit_transform
# entities = @model.active_entities
p "@编辑中组件tr="+@编辑中组件tr.to_a.to_s
p "kk:"+Geom::Point3d.new(0,0,0).transform(@编辑中组件tr).to_s
# tr=@编辑中组件tr.inverse
# p "@编辑中组件tr="+@编辑中组件tr.to_a.to_s
# p "tr="+tr.to_a.to_s


@model = Sketchup.active_model
@编辑中组件tr=Sketchup.active_model.edit_transform
kk=Geom::Point3d.new(0,0,0).transform(@编辑中组件tr)
p "kk:"+kk.to_s
tr=@编辑中组件tr.inverse
kkf=kk.transform(tr)
p "kkf:"+kkf.to_s

@model = Sketchup.active_model
@编辑中组件tr=Sketchup.active_model.edit_transform
kk=Geom::Point3d.new(1126.539699, -876.247148, 400).transform(@编辑中组件tr)
p "kk:"+kk.to_s





# p "kk:"+Geom::Point3d.new(1568.148555, -827.465945, 400).transform(tr).to_s

# # entities = @model.active_entities
# p "@编辑中组件tr="+@编辑中组件tr.to_a.to_s
# gtr = Geom::Transformation.new
# gtr = gtr / @编辑中组件tr
# p "gtr:"+gtr.to_a.to_s


@model = Sketchup.active_model
entities = @model.active_entities
line = entities.add_line  Geom::Point3d.new(0,0,0), Geom::Point3d.new(-974.501569, -117.074205, 98.970848)
line = entities.add_line  Geom::Point3d.new(0,0,0), Geom::Point3d.new(-1010.78431, -205.12424, 0)

@model = Sketchup.active_model
entities = @model.active_entities
line = entities.add_line  Geom::Point3d.new(0,0,0), Geom::Point3d.new(10,10,0)

@model = Sketchup.active_model
ent = @model.entities
line = ent.add_line  Geom::Point3d.new(0,0,0), Geom::Point3d.new(10,10,0)

@model = Sketchup.active_model
selection = @model.selection
gp = selection[0].definition.entities
gp = gp.add_line  Geom::Point3d.new(0,0,0), Geom::Point3d.new(10,10,0)

@model = Sketchup.active_model
selection = @model.selection
面 = selection[0]
面.vertices.each{|vt|
  vtp=vt.position
  p "vtp转换前："+vtp.to_s
  # vtp=vtp.transform( tr )
  # p "vtp转换后："+vtp.to_s
}



# 构造XYZ轴的6个方向的raytest列表,获取投影元素
  item_list = []
  [1, -1].each do |vec|
    (0..2).each do |i|
    cu_vec = Geom::Vector3d.new(0, 0, 0)
    cu_vec[i] = vec
    item_list << @model.raytest([偏移点, cu_vec], true)
  end
end
# 解析投影元素，存储内部空间的5个面
inner_faces = []
p "item_list.count="+item_list.count.to_s
item_list.each do |item|
  if item != nil
    # 过滤投影得到的面
    item_faces = item[1].select { |i| i.is_a? Sketchup::Face }
    # 去除没有投影面的
    inner_faces << item_faces[0] unless item_faces.empty?
  end
end
selection.add(inner_faces)



              if ar右 != nil
                击中点=ar右[0]
                @右面x=击中点[0]
                line = @entities.add_line @原点,Geom::Point3d.new(击中点)
              end
              if ar上 != nil
                击中点=ar上[0]
                @右面x=击中点[0]
                line = @entities.add_line @原点,Geom::Point3d.new(击中点)
              end
              if ar下 != nil
                击中点=ar下[0]
                @右面x=击中点[0]
                line = @entities.add_line @原点,Geom::Point3d.new(击中点)
              end



              # if 选择的面="内空左面" then
              #   # 识别击中ar(ar右)
              #   if ar右 != nil
              #     击中点=ar右[0]
              #     @右面x=击中点[0]
              #     # line = @entities.add_line @原点,Geom::Point3d.new(@右面x, @后面y, @下面z)
              #   end
              #   if ar前 != nil
              #     击中点=ar前[0]
              #     @前面y=击中点[1]
              #   end
              #   击中点=ar下[0]
              #   @下面z=击中点[2]
              #   击中点=ar上[0]
              #   @上面z=击中点[2]
              # end
              # @左下后点p=Geom::Point3d.new(@左面x, @后面y, @下面z)
              # @右下后点p=Geom::Point3d.new(@右面x, @后面y, @下面z)
              # @width = @左下后点p.distance @右下后点p

              # @左下前点p=Geom::Point3d.new(@左面x, @前面y, @下面z)
              # @depth = @左下后点p.distance @左下前点p

              # @左上后点p=Geom::Point3d.new(@左面x, @后面y, @上面z)
              # @height = @左下后点p.distance @左上后点p

              # # p "选择面法向.round="+选择面法向.to_s
              # @左下后点p=nil
              # 选择的面=""
              # case 选择面法向
              #   when Geom::Vector3d.new(1,0,0)
              #     选择的面="内空左面"
              #     p "选择了"+选择的面
              #     # @左下后点p=@ip.face.vt0p.transform( 选择点tr )
              #     # @ip.face.vertices.each{|vt|
              #     #   vtp=vt.position.transform( 选择点tr )
              #     #   y值=vtp[1]
              #     #   if y值<@左下后点p[1]
              #     #     @左下后点p[1]=y值
              #     #   end
              #     # }
              #     识别面对角点(@ip.face,选择点tr)
              #     @左面x=@最小x
              #     @前面y=@最大y
              #     @后面y=@最小y
              #     @上面z=@最大z
              #     @下面z=@最小z
              #     # p "@左面x……"
              #     # p @左面x
              #     # p @后面y
              #     # p @下面z
              #     # line = @entities.add_line @原点,Geom::Point3d.new(@左面x, @后面y, @下面z)
              #   when Geom::Vector3d.new(-1,0,0)
              #     选择的面="内空右面"
              #     识别面对角点(@ip.face,选择点tr)
              #     @右面x=@最小x
              #     @前面y=@最大y
              #     @后面y=@最小y
              #     @上面z=@最大z
              #     @下面z=@最小z
              # end

              kk=nil
              kk==nil ? kk="yy" : kk="jj"

                  # def 在单击点画矩形
    #   z1 = $ent.add_group
    #   fx1 = z1.@@entities.add_face [0,0,0],[50,0,0],[50,50,0],[0,50,0]
    #   fx1_f = fx1.pushpull -50
    #   $ent.transform_@@entities @ip,z1
    # end



  # cm1 = UI::Command.new("g"){
  # Sketchup.active_model.select_tool Tom1.new
  # }

  # toolbar = UI::Toolbar.new"t1z"
  # toolbar.add_item cm1
  # toolbar.show
